package utils.test;

import java.util.Collection;
import java.util.Map;

import utils.bean.ObjectUtils;

/**
 * 测试工具包
 * @author 曹炳俊
 * @since 2011-9-22
 */
public class Assert {
	
	private Assert() {
	}
	
	/**
	 * 断言对象非空
	 * @param o
	 */
	public static void isNotNull(Object o,String assertMsg){
		if (ObjectUtils.isNull(o)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言对象为空
	 * @param o
	 */
	public static void isNull(Object o,String assertMsg){
		if (ObjectUtils.isNotNull(o)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言两个对象相等
	 * @param o1
	 * @param o2
	 * @param assertString
	 */
	public static void isEquals(Object o1,Object o2,String assertMsg){
		isNotNull(o1, "不能传入空对象");
		if (ObjectUtils.isNotEquals(o1, o2)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言两个对象不相等
	 * @param o1
	 * @param o2
	 * @param assertString
	 */
	public static void isNotEquals(Object o1,Object o2,String assertMsg){
		isNotNull(o1, "不能传入空对象");
		if (ObjectUtils.isEquals(o1, o2)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言两个数值相等
	 * @param o1
	 * @param o2
	 * @param assertMsg
	 */
	public static void isEquals(int o1,int o2,String assertMsg){
		if (ObjectUtils.isNotEquals(o1, o2)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言两个数值不相等
	 * @param o1
	 * @param o2
	 * @param assertMsg
	 */
	public static void isNotEquals(int o1,int o2,String assertMsg){
		if (ObjectUtils.isEquals(o1, o2)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言数组有长度
	 * @param arr
	 * @param assertMsg
	 */
	public static void hasLength(Object[] arr,String assertMsg){
		if (ObjectUtils.hasNotLength(arr)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言数组无长度
	 * 空或长度为0都表示无长度
	 * @param arr
	 * @param assertMsg
	 */
	public static void hasNotLength(Object[] arr,String assertMsg){
		if (ObjectUtils.hasLength(arr)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言集合有长度
	 * @param c
	 * @param assertMsg
	 */
	public static void hasLength(Collection<?> c,String assertMsg){
		if (ObjectUtils.hasNotLength(c)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言集合无长度
	 * @param c
	 * @param assertMsg
	 */
	public static void hasNotLength(Collection<?> c,String assertMsg){
		if (ObjectUtils.hasLength(c)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言Map有长度
	 * @param m
	 * @param assertMsg
	 */
	public static void hasLength(Map<?,?> m,String assertMsg){
		if (ObjectUtils.hasNotLength(m)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
	
	/**
	 * 断言Map有长度
	 * @param m
	 * @param assertMsg
	 */
	public static void hasNotLength(Map<?,?> m,String assertMsg){
		if (ObjectUtils.hasLength(m)) {
			throw new IllegalArgumentException(assertMsg);
		}
	}
}
